import httpClient from "./http-client";

export class AuthService {
    baseUrl = "/api/v1.0/portal/auth";
    verifyCodeUrl = `${this.baseUrl}/verify-code`;

    async getVerifyCode() {
        return httpClient.get(`${this.baseUrl}/verify-code?timestamp=${new Date().getTime()}`, false);
    }

    async login(param) {
        return httpClient.post(`${this.baseUrl}/login`, {
            ...param,
        }, false);
    }

    async logout() {
        return httpClient.post(`${this.baseUrl}/logout`);
    }

    async register(param) {
        return httpClient.post(`${this.baseUrl}/register`, param);
    }

    async checkUsername(username) {
        return httpClient.get(`${this.baseUrl}/check/username/${username}`);
    }

    async checkEmail(email) {
        return httpClient.get(`${this.baseUrl}/check/email/${email}`);
    }

    async checkPhone(phone) {
        return httpClient.get(`${this.baseUrl}/check/phone/${phone}`);
    }

    async checkUsernameBeforeResetPassword(username) {
        return httpClient.get(`${this.baseUrl}/forget-password/check/username/${username}`);
    }

    async checkMainInfoBeforeReset(param) {
        return httpClient.post(`${this.baseUrl}/forget-password/check`, {
            ...param,
        });
    }

    async resetPassword(param) {
        return httpClient.put(`${this.baseUrl}/forget-password/reset`, {
            ...param,
        });
    }
}

const authService = new AuthService();

export default authService;